<%-- 
  - Author: Ismail
  - Date: 26-Apr-2012
  - Copyright Notice: TRAKHEES
  - Description: form.jsp
 --%>

<%@ include file="/WEB-INF/view/include.jsp"%>
<%@ page import="ae.pcfc.etks.online.web.*"%>

<c:choose>
	<c:when
		test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
		<script language="Javascript" type="text/javascript"
			src='<c:url value="/resources/js/jqgrid/grid.locale-ar.js"/>'></script>
	</c:when>
	<c:otherwise>
		<script language="Javascript" type="text/javascript"
			src='<c:url value="/resources/js/jqgrid/grid.locale-en.js"/>'></script>
	</c:otherwise>
</c:choose>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.base.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.common.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.formedit.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.inlinedit.js"/>'></script>

<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.custom.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/jquery.fmatter.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.filter.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.jqueryui.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.import.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.grouping.js"/>'></script>
<script type="text/javascript">
    $.jgrid.no_legacy_api = true;
    $.jgrid.useJSON = true;
</script>


<script type="text/javascript">
	$()
			.ready(
					
					function() {
						$('input[name=clientType]').change(function() {
					        var clientType= $("input[name=clientType]:checked").val();
					        if(clientType=='C'){
					        	$("#clientName").attr("disabled","disabled");
					            $("#trakheesId").removeAttr("disabled");
					        }else{
					        	$("#trakheesId").attr("disabled","disabled");
					            $("#clientName").removeAttr("disabled");
					        }
					    });
						$('input[name=clientType]').trigger('change');
						/*$('#trakheesId').attr('placeholder','<spring:message code="msg.search.by.trakhees.id.hint" />');
						$('#trakheesId').autocomplete({
							source: function(request, response) {
								$.ajax({
									url: "${pageContext.request.contextPath}/user/internal/workflow/search/client.json",
									dataType: "json",
									contentType: "application/json; charset=utf-8",
									data: {
										term : request.term									
									},
									success: function(data) {
										response(data);
									}
								});
							},
							minLength: 1,
							mustMatch: true,
							delay: 1000,
							select: function( event, ui ) {
								$('input[name=trakheesId]').val(ui.item.id);
							}
						}); */


						$('#statusCode').autocomplete({
							source: function(request, response) {
								$.ajax({
									url: "${pageContext.request.contextPath}/user/internal/workflow/search/requestStatus.json",									
									dataType: "json",
									responseType:"application/json; charset=utf-8",
								    contentType:"application/json; charset=utf-8",
									data: {
										term : request.term									
									},
									success: function(data) {
										response(data);
									}
								});
							},
							minLength: 1,
							mustMatch: true,
							delay: 1000,
							select: function( event, ui ) {
								$('input[name=statusCode]').val(ui.item.id);
							}
						}); 
						
						jQuery("#grid").jqGrid({
							 datatype :'local',					  
							 autowidth: true, 
							 height: 'auto', 
							 rowNum: 10, 
							 rowList: [10,20,30], 
							 colNames:['<spring:message code="label.id" />','<spring:message code="label.user.request.reference.no" />','<spring:message code="label.incident.id" />', '<spring:message code="label.process.code" />','<spring:message code="label.workflow.request.desc" />', '<spring:message code="label.workflow.request.desc" />', '<spring:message code="label.search.status" />', '<spring:message code="label.search.status" />','<spring:message code="label.application.link" />','<spring:message code="label.admin.action" />'],
							 colModel:[ 
										 {name:'strApplicationId',index:'strApplicationId', width:100,sortable : true},
										 {name:'strClientRefNo',index:'strClientRefNo', width:200,sortable : false},
										 {name:'strWFIncidentId',index:'strWFIncidentId', width:200,sortable : true},
										 {name:'strProcessCode',index:'strProcessCode', width:0,sortable : true, hidden: true},
										 {name:'strProcessCodeDescAr',index:'strProcessCodeDescAr', width:600,sortable : true								 
										 <c:choose>
											 <c:when test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
										 		},	 
											 </c:when>
											 <c:otherwise>
												,hidden:true},
											 </c:otherwise>
										 </c:choose>
										 {name:'strProcessCodeDescEn',index:'strProcessCodeDescEn', width:600,sortable : true
										<c:choose>
											 <c:when test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
											 	,hidden:true},	 
											 </c:when>
											 <c:otherwise>
											 	},
											 </c:otherwise>
										 </c:choose>
										 {name:'strStatusDescAr',index:'strStatusDescAr', width:600,sortable : true								 
											 <c:choose>
												 <c:when test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
											 		},	 
												 </c:when>
												 <c:otherwise>
													,hidden:true},
												 </c:otherwise>
											 </c:choose>
											 {name:'strStatusDescEn',index:'strStatusDescEn', width:600,sortable : true
											<c:choose>
												 <c:when test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
												 	,hidden:true},	 
												 </c:when>
												 <c:otherwise>
												 	},
												 </c:otherwise>
											 </c:choose>
										 {name:'strApplicationLink',index:'strApplicationLink', width:0,sortable : true, hidden: true},										 
										 {name:'action', sortable: false, width:200, formatter:function(){
											 var queryParams = 'appid='+arguments[2][9];
											 var queryParams1 = 'appid='+arguments[2][9]+'&Incident='+arguments[2][10];
											 if(arguments[2][3] == 'NCCR'){
												 return '<a target="_blank" href="${pageContext.request.contextPath}/admin/workflow/general/company/request/nonclient/show.htm?'+queryParams1+'" ><spring:message code="label.user.request.view"/></a>';
											}else if(arguments[2][3] == 'NCPR'){
												return '<a target="_blank" href="${pageContext.request.contextPath}/admin/workflow/general/person/request/nonclient/show.htm?'+queryParams+'" ><spring:message code="label.user.request.view"/></a>';
											}else if(arguments[2][3] == 'CCR'){
												return '<a target="_blank" href="${pageContext.request.contextPath}/admin/workflow/general/company/request/client/show.htm?'+queryParams1+'" ><spring:message code="label.user.request.view"/></a>';
											}else if(arguments[2][3] == 'CPR'){
												return '<a target="_blank" href="${pageContext.request.contextPath}/admin/workflow/general/person/request/client/show.htm?'+queryParams+'" ><spring:message code="label.user.request.view"/></a>';
											}else if(arguments[2][3] == 'CRR'){
												return '<a target="_blank" href="${pageContext.request.contextPath}/admin/workflow/general/role/request/show.htm?'+queryParams+'" ><spring:message code="label.user.request.view"/></a>';
											}else if(arguments[2][3] == 'SR'){
												return '<a target="_blank" href="${pageContext.request.contextPath}/admin/workflow/general/service/request/show.htm?'+queryParams+'" ><spring:message code="label.user.request.view"/></a>';
											}
										      return '<a target="_blank" href="'+ arguments[2][8] +'"><spring:message code="label.user.request.view"/></a>';
										  }} 
										],
							pager: "#pager",
							viewrecords: true,
						 <c:choose>
							 <c:when test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
							 sortname:  'strProcessCodeDescAr', 
							 </c:when>
							 <c:otherwise>
							 sortname:  'strProcessCodeDescEn',
							 </c:otherwise>
						 </c:choose>
							caption: '<spring:message code="label.search.workflow.results" />'
							<c:if test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
							, direction:'rtl'
							</c:if>	
						});
						$("#searchbtn").click(function(){
							$("#grid").setGridParam(
									{
										datatype:'json',
										mtype: 'POST',
										url	:'${pageContext.request.contextPath}/user/internal/workflow/search/form.htm',
										postData: {clientRefNo:$("#clientRefNo").val(),
											wfIncidentId:$("#wfIncidentId").val(),
											statusCode:$("#statusCode").val(),
											processCode:$("#processCode").val(),
											clientName:$("#clientName").val(),
										    trakheesId:$("#trakheesId").val(),
										    licenseNo:$("#licenseNo").val()
										 }
									}).trigger("reloadGrid");
						});			
						$("#SearchRequest")
								.validate(
										{
											onfocusout : false,
											onkeyup : false,
											onclick : false,
											rules : {
											},

											showErrors : function(errorMap,
													errorList) {

												var errors = '<ul>';
												var label;
												if (errorList.length) {
													$.each(errorMap, function(
															name, value) {
														label = $(
																"label[for='"
																		+ name
																		+ "']")
																.html();
														label = value + '['
																+ label + ']';
														errors = errors
																+ '<li>'
																+ label
																+ '</li>';

													});
													errors = errors + '</ul>';
													jAlert('error', errors,
															'<spring:message code="label.errormessage" />');
												}
											}

										});
			
					});
	
	
</script>



<div id="container" dir='<spring:message code="page.dir"/>'
	align='<spring:message code="page.align"/>' >


	<form:form name="SearchRequest" id="SearchRequest" method="POST"
		modelAttribute="<%=ConstantsAdmin.SEARCH_WORKFLOW_REQUEST_MODEL_KEY %>">


		<spring:hasBindErrors
			name="<%=ConstantsAdmin.SEARCH_WORKFLOW_REQUEST_MODEL_KEY %>">
			<script type="text/javascript">
				$(document)
						.ready(
								function() {
									jAlert(
											'error',
											'<li><form:errors path="*" delimiter="<li>"/>',
											'<spring:message code="label.errormessage" />');
								});
			</script>
		</spring:hasBindErrors>
		
	
	<div class="ui-widget_c ui-corner-all" dir='<spring:message code="page.dir"/>'
	align='<spring:message code="page.align"/>' >
	
	<div class="ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix"><spring:message code="label.search.workflow.request" /></div>
	<div style="clear:both"><br/><br/></div>	
	<div>
		<div class="t_form_half float">
			<div class="fm-req">
				<form:label path="clientName">
					<spring:message code="label.search.client.name" />
				</form:label>
				<form:input path="clientName" id="clientName" size="50"
					maxlength="100"/>
			</div>			
			<div class="fm-req">
				<form:label path="trakheesId">
					<spring:message code="label.user.request.trakhees.id" />
				</form:label>
				<form:input path="trakheesId" id="trakheesId" size="20"
					maxlength="100"/>
			</div>
			
			<div class="fm-req">
				<form:label path="licenseNo">
					<spring:message code="label.search.license.number" />
				</form:label>
				<form:input path="licenseNo" id="licenseNo" size="20"
				maxlength="50"/>
			</div>
			
			<div class="fm-req">
				<form:label path="statusCode">
					<spring:message code="label.search.status" />
				</form:label>
				<form:input path="statusCode" id="statusCode" size="20"
				maxlength="50"/>
			</div>
			
		</div>
		
		<div class="t_form_half float">
			<div class="fm-req">
				<form:label path="clientRefNo">
					<spring:message code="label.search.client.ref.no" />
				</form:label>
				<form:input path="clientRefNo" id="clientRefNo" size="20"
					maxlength="100"/>
			</div>			
			<div class="fm-req">
				<form:label path="wfIncidentId">
					<spring:message code="label.search.incident.no" />
				</form:label>
				<form:input path="wfIncidentId" id="wfIncidentId" size="20"
					maxlength="100"/>
			</div>
			
			 <div class="fm-req">
				<form:label path="processCode">
					<spring:message code="label.search.request.type" />
				</form:label>
				<c:choose>
					<c:when
						test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
						<form:select path="processCode"
							items="${requestTypeListModel}"
							id="processCode" itemLabel="labelAr"
							itemValue="id" cssStyle="width:150px;" class="fm-opt"/>
					</c:when>
					<c:otherwise>
						<form:select path="processCode"
							items="${requestTypeListModel}"
							id="processCode" itemLabel="labelEn"
							itemValue="id" cssStyle="width:150px;" class="fm-opt"/>
					</c:otherwise>
				</c:choose>
			</div>
			
		</div>		
	</div>
	<div style="clear:both"></div>	
		<div id="fm-submit" class="fm-req">
				<input type="button" name="search" id="searchbtn" value="<spring:message code="label.button.search" />" class="t_btns submit"/>
				<input type="reset" name="reset" value="<spring:message code="label.button.reset" />" class="t_btns submit"/>
		</div>
	</div>
	</form:form>

		<div id="search"></div>
		<table id="grid" width="100%">
		</table>
		<span id="pager"></span>
</div>
